package com.augurit.gzcgwsp.rqqyjyxk.web;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.form.Attachment;
import com.augurit.common.syscode.service.ISysCodeService;
import com.augurit.common.syscode.web.form.SysCodeForm;
import com.augurit.common.syslog.tool.SysTraceLogWriter;
import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.common.exp.PoiExcelSheetCopy;
import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.excelimportexport.service.IYwRqQyjyxkImportservice;
import com.augurit.gzcgwsp.excelimportexport.util.FileUtil;
import com.augurit.gzcgwsp.excelimportexport.util.GetFileName;
import com.augurit.gzcgwsp.rqqyjyxk.entity.YwRqQyjyxk;
import com.augurit.gzcgwsp.rqqyjyxk.service.IYwRqQyjyxkService;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.PzrqgyzdjbForm;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.RqssdjbForm;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.YwRqQyjyxkForm;
import com.augurit.gzcgwsp.rqqyjyxk.web.form.YwRqQyjyxkfbForm;
import com.augurit.gzcgwsp.ssylb.entity.YwRqRqssylb;
import com.augurit.gzcgwsp.webservice.SFTPUtil;
import com.augurit.gzcgwsp.webservice.service.IKingdomDataForRqsjService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComQyxxService;
import com.augurit.gzcgwsp.ywcmn.service.IYwComSjclService;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComSjclForm;
import com.augurit.wf.bi.service.IWfBusTemplateService;
import com.augurit.wf.bi.web.form.WfBusInstanceTaskForm;
import com.augurit.wf.bi.web.form.WfBusTemplateForm;
import com.augurit.wf.common.form.WfBusSaveResult;
import com.augurit.wf.common.service.IWfBusClientService;
import com.augurit.wf.common.service.IWfService;
import com.augurit.wf.common.util.WfUtils;
import com.augurit.wf.common.web.WfBusClientAction;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "yw-rq-qyjyxk.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxk.jsp"),
	@Result(name = "preViewJyxkz", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/preViewJyxkz.jsp"),
	@Result(name = "gzViewXkz", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/gzViewXkz.jsp"),
	@Result(name = "gzViewFb", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/gzViewFb.jsp"),
	@Result(name = "gzViewGyssxkbs", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/gzViewGyssxkbs.jsp"),
	@Result(name = "printJyxkz", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/printJyxkz.jsp"),
	@Result(name = "printJyxkzfb", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/printJyxkzfb.jsp"),
	@Result(name = "preViewJyxkzfb", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/preViewJyxkzfb.jsp"),
	@Result(name = "preViewGyssxkbs", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/preViewGyssxkbs.jsp"),
	@Result(name = "printGyssxkbs", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/printGyssxkbs.jsp"),
	@Result(name = "PRINT", location = "/gzcgwsp/wfex/client/wf-printEx.jsp"),
	@Result(name = "printnewXkz", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/printnewXkz.jsp"),
	@Result(name = "viewkHFile", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/viewkHFile.jsp"),
	@Result(name = "printJyxkzs", location = "/gzcgwsp/wfex/client/wf-printEx.jsp"),
	@Result(name = "showData", location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/showCheckData.jsp"),
	@Result(name = "printJyxkfbzs", location = "/gzcgwsp/wfex/client/wf-printExcelEx.jsp"),
	@Result(name = CrudActionSupport.INPUT, location = "/gzcgwsp/rqqyjyxk/YwRqQyjyxk/YwRqQyjyxk-input.jsp")
	
})
public class YwRqQyjyxkAction extends WfBusClientAction<YwRqQyjyxkForm>{
	private final static Log log=LogFactory.getLog(YwRqQyjyxkAction.class);
	@Autowired
	private IYwRqQyjyxkService ywRqQyjyxkService;
    @Autowired
    private ISysCodeService syscodeService;
    @Autowired
    private IYwComQyxxService qyxxService;
    @Autowired
    private IWfBusTemplateService wfBusTemplateService;
    @Autowired
	private IYwComSjclService ywComSjclService;
    @Autowired
	private IWfService wfService;
	//上传的附件--主要是经营许可的考核表
	private File[] attachment;
    
    @Autowired
	private IYwRqQyjyxkImportservice ywRqQyjyxkImportservice;
    @Autowired
    private IKingdomDataForRqsjService kingdomDataForRqsjService;
    
	private YwRqQyjyxkForm form;
	private Long id;
	private Long[] checkedIds;
	private Page<YwRqQyjyxkForm> page = new Page<YwRqQyjyxkForm>(10);
	
	/*经营许可证副本打印*/
	private YwRqQyjyxkfbForm fb;
	private String[] mj;
	private String[] zw;
	private String[] zc;	
	private String[] rqssXh;
	private String[] rqssMc;
	private String[] rqssDz;
	private String[] rqssSslb;	
	private String[] pzrqXh;
	private String[] pzrqMc;
	private String[] pzrqDz;
	private String[] pzrqGyzdj;
	private String fbPath;
	/*经营许可证副本打印*/
	
	
	/**
	 * 预览套打经营许可证
	 * @return
	 */
	public String gzViewXkz(){
	    this.dateUtil();    //设置有效时间
	    if(form.getZsbh()==null){
	    	String zsbh=ywRqQyjyxkService.createCardNo(form,1);
	    	form.setZsbh(zsbh);
	    }
	    String tempPath="Templates/rqjyxk/rqjyxk.xls";
    	 if(form.getTemplateCode().contains("qx")){
 	    	form.setFzjg(this.getLoginUser().getOrg().getOrgName());
 	    }else{
 	    	form.setFzjg("广州市城市管理委员会");
 	    }
        try {
            String context=getRequest().getSession().getServletContext().getRealPath("");
            tempPath=ywRqQyjyxkService.writeXkzData(form,context);
            getRequest().setAttribute("templateFilePath",tempPath);
        } catch (Exception e) {
            log.error("转换模版文件出现错误");
        }
        
		return "gzViewXkz";
	}
	
	public void setgzXkz(){
	    this.dateUtil();    //设置有效时间
	    if(form.getZsbh()==null){
	    	String zsbh=ywRqQyjyxkService.createCardNo(form,1);
	    	form.setZsbh(zsbh);
	    }
	    String tempPath="Templates/rqjyxk/rqjyxk.xls";
    	 if(form.getTemplateCode().contains("qx")){
 	    	form.setFzjg(this.getLoginUser().getOrg().getOrgName());
 	    }else{
 	    	form.setFzjg("广州市城市管理委员会");
 	    }
        try {
            String context=getRequest().getSession().getServletContext().getRealPath("");
            tempPath=ywRqQyjyxkService.writeXkzData(form,context);
            getRequest().setAttribute("templateFilePath",tempPath);
        } catch (Exception e) {
            log.error("转换模版文件出现错误");
        }
      
	}
	
	
	/**
	 * 预览套打经营许可证
	 * @return
	 */
	public String gzViewFb(){
        this.dateUtil();    //设置有效时间
        List<YwComSjclForm> ycsList = ywComSjclService.getList(this.getTemplateCode(), id, "燃气经营许可证（副本）");
        if(ycsList != null && ycsList.size() > 0){
            fbPath = ycsList.get(0).getFilepath();
        }
        //根据附件获取副本的值
        YwRqQyjyxkfbForm yrf = ywRqQyjyxkService.getYwRqQyjyxkfb(this.getSysRealPath(),fbPath,id);
        fb = yrf;
       if(StringUtils.isNotBlank(fb.getZczb())){
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
       if(StringUtils.isNotBlank(form.getZsbh())){
           fb.setYyzzzch(form.getZsbh());//证书编号
       }
       if(StringUtils.isNotBlank(form.getGszcdjh())){
           fb.setYyzzzch(form.getGszcdjh());//营业号
       }
       if(form.getZsbh()==null){
           ywRqQyjyxkService.createZsbh(form,1,null,false);
       }
       
       //发证日期
       if(StringUtils.isNotBlank(fb.getFzrq())){
           try {
			DateUtilsEX.convertDate2Chinese(new Date());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       }
       
       String hjmc=getRequest().getParameter("hjmc");
       getRequest().setAttribute("hjmc", hjmc);
       fb.setXkzbh(form.getZsbh());
        if(StringUtils.isNotBlank(fb.getZczb())){//注册资本设置
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
        if(StringUtils.isNotBlank(form.getGszcdjh())){
               fb.setYyzzzch(form.getGszcdjh());
          }
        if(form.getZsbh()==null){
               ywRqQyjyxkService.createZsbh(form,1,null,false);
               ywRqQyjyxkService.saveQyjyxk(form,1);//保存证书
         }
        
        if(form.getZsbh()==null){
            ywRqQyjyxkService.createZsbh(form,1,null,false);
        }
        fb.setFbzsbh(form.getZsbh());
         getRequest().setAttribute("hjmc", hjmc);
        String path="Templates/rqjyxk/rqjyxkfb.xls";
        String context=getRequest().getSession().getServletContext().getRealPath("");
        // String path="Templates/rqjyxk/rqjyxkfb.xls";
         logger.info("打印经营许可证的文件路径"+path);
        try {
            //构造燃气设施登记表
    	    Map<String,List<RqssdjbForm>> rqssMap=buildRqssdjs();
    	    //构造瓶装燃气供应站登记表
    	    Map<String,List<PzrqgyzdjbForm>> pzMap=buildPzRqssdjs();
    	    String hasFb="";
    	    List<RqssdjbForm> list=ywRqQyjyxkService.getRqssdjbForm(form,true);
    	    if(list!=null && list.size()>0){
    	    	//没有将是否追加的标志保存到数据库，所以只要有一列设施保存了打印到多少页。就为追加的方式打印
    	    	RqssdjbForm rqss=list.get(0);
    	    	if(StringUtils.isNotBlank(rqss.getPagenum())){
    	    		hasFb="y";
    	    	}
    	    }
    	    if("y".equals(hasFb)){
    	    	 path=ywRqQyjyxkService.writeData(form,fb,context,rqssMap,pzMap);
    	    }else{
    	    	 path=ywRqQyjyxkService.writeData(form,fb,context);
    	    }
            getRequest().setAttribute("templateFilePath",path);
            //getRequest().setAttribute(WfConstant.PRINT_BUFFER, variables);
 
        } catch (Exception e) {
        	e.printStackTrace();
            log.error("转换模版文件出现错误"+e);
        }
		return "gzViewFb";
	}
	
	/**
	 * 预览套打经营许可证
	 * @return
	 */
	public String preViewJyxkz(){
	    this.dateUtil();    //设置有效时间
	    if(form.getZsbh()==null){
	    	String zsbh=ywRqQyjyxkService.createCardNo(form,1);
	    	form.setZsbh(zsbh);
	    }
	   
    	 if(form.getTemplateCode().contains("qx")){
 	    	form.setFzjg(this.getLoginUser().getOrg().getOrgName());
 	    }else{
 	    	form.setFzjg("广州市城市管理委员会");
 	    }
	  
	    String hjmc=getRequest().getParameter("hjmc");
	    getRequest().setAttribute("hjmc", hjmc);
	    if("dzgz".equals(hjmc)){
	    	setgzXkz();
	    }
		return "preViewJyxkz";
	}
	
	/**
	 * 套打经营许可证
	 * @return
	 */
	public String printJyxkz(){
		ywRqQyjyxkService.saveQyjyxk(form,1);
	      if(StringUtils.isNotBlank(form.getGqqy())){
              this.getRequest().setAttribute("ggqylength", form.getGqqy().length());
          }
          if(StringUtils.isNotBlank(form.getAddress())){
             form.setAddresslength(form.getAddresslength());
          }
          
		return "printJyxkz";
	}
	
	/**
	 * 预览套打经营许可证副本
	 * @return
	 */
	public String preViewJyxkzfb(){
		List<YwComSjclForm> ycsList = ywComSjclService.getList(this.getTemplateCode(), id, "燃气经营许可证（副本）");
		
		if(ycsList != null && ycsList.size() > 0){
			fbPath = ycsList.get(0).getFilepath();
		}
		//根据附件获取副本的值，现在所有的副本都不存在文件路径，都统一从数据库查询数据
		YwRqQyjyxkfbForm yrf = ywRqQyjyxkService.getYwRqQyjyxkfb(this.getSysRealPath(),fbPath,id);
		fb = yrf;
		if(StringUtils.isBlank(fb.getZczb())){
			fb.setZczb(form.getZczj());//设置注册资本
		}
	   if(StringUtils.isNotBlank(fb.getZczb())){
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
	   if(StringUtils.isBlank(fb.getFzjg())){
		   if(form.getTemplateCode().contains("qu")){
			   fb.setFzjg(getLoginUser().getOrg().getOrgName());
		   }else{
			   fb.setFzjg("广州市城市管理委员会");
		   }
	   }
	   if(StringUtils.isBlank(fb.getFzrq())){
		   //发证日期
		   fb.setFzrq(DateUtilsEX.getCurYear()+"年"+DateUtilsEX.getCurMonth()+"月"+DateUtilsEX.getCurDay()+"日");
	   }
	   if(StringUtils.isNotBlank(form.getZsbh())){
           fb.setYyzzzch(form.getZsbh());//证书编号
       }
	   if(StringUtils.isNotBlank(form.getGszcdjh())){
	       fb.setYyzzzch(form.getGszcdjh());//营业号
	   }
	   if(form.getZsbh()==null){
           ywRqQyjyxkService.createZsbh(form,1,null,false);
       }
	   String hjmc=getRequest().getParameter("hjmc");
	   if("dzgz".equals(hjmc)){
		   this.setGzFb();
	   }
       getRequest().setAttribute("hjmc", hjmc);
	   fb.setXkzbh(form.getZsbh());
	   fb.setFbzsbh(form.getZsbh());
		return "preViewJyxkzfb";
	}
	
	/**
	 * 预览套打经营许可证
	 * @return
	 */
	public String setGzFb(){
        this.dateUtil();    //设置有效时间
        List<YwComSjclForm> ycsList = ywComSjclService.getList(this.getTemplateCode(), id, "燃气经营许可证（副本）");
        if(ycsList != null && ycsList.size() > 0){
            fbPath = ycsList.get(0).getFilepath();
        }
        //根据附件获取副本的值
        YwRqQyjyxkfbForm yrf = ywRqQyjyxkService.getYwRqQyjyxkfb(this.getSysRealPath(),fbPath,id);
        fb = yrf;
       if(StringUtils.isNotBlank(fb.getZczb())){
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
       if(StringUtils.isNotBlank(form.getZsbh())){
           fb.setYyzzzch(form.getZsbh());//证书编号
       }
       if(StringUtils.isNotBlank(form.getGszcdjh())){
           fb.setYyzzzch(form.getGszcdjh());//营业号
       }
       if(form.getZsbh()==null){
           ywRqQyjyxkService.createZsbh(form,1,null,false);
       }
       
       //发证日期
       if(StringUtils.isNotBlank(fb.getFzrq())){
           try {
			DateUtilsEX.convertDate2Chinese(new Date());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       }
       
       String hjmc=getRequest().getParameter("hjmc");
       getRequest().setAttribute("hjmc", hjmc);
       fb.setXkzbh(form.getZsbh());
        if(StringUtils.isNotBlank(fb.getZczb())){//注册资本设置
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
        if(StringUtils.isNotBlank(form.getGszcdjh())){
               fb.setYyzzzch(form.getGszcdjh());
          }
        if(form.getZsbh()==null){
               ywRqQyjyxkService.createZsbh(form,1,null,false);
               ywRqQyjyxkService.saveQyjyxk(form,1);//保存证书
         }
        
        if(form.getZsbh()==null){
            ywRqQyjyxkService.createZsbh(form,1,null,false);
        }
        fb.setFbzsbh(form.getZsbh());
         getRequest().setAttribute("hjmc", hjmc);
        String path="Templates/rqjyxk/rqjyxkfb.xls";
        String context=getRequest().getSession().getServletContext().getRealPath("");
        // String path="Templates/rqjyxk/rqjyxkfb.xls";
         logger.info("打印经营许可证的文件路径"+path);
        try {
            //构造燃气设施登记表
    	    Map<String,List<RqssdjbForm>> rqssMap=buildRqssdjs();
    	    //构造瓶装燃气供应站登记表
    	    Map<String,List<PzrqgyzdjbForm>> pzMap=buildPzRqssdjs();
    	    String hasFb="";
    	    List<RqssdjbForm> list=ywRqQyjyxkService.getRqssdjbForm(form,true);
    	    if(list!=null && list.size()>0){
    	    	//没有将是否追加的标志保存到数据库，所以只要有一列设施保存了打印到多少页。就为追加的方式打印
    	    	RqssdjbForm rqss=list.get(0);
    	    	if(StringUtils.isNotBlank(rqss.getPagenum())){
    	    		hasFb="y";
    	    	}
    	    }
    	    if("y".equals(hasFb)){
    	    	 path=ywRqQyjyxkService.writeData(form,fb,context,rqssMap,pzMap);
    	    }else{
    	    	 path=ywRqQyjyxkService.writeData(form,fb,context);
    	    }
            getRequest().setAttribute("templateFilePath",path);
            //getRequest().setAttribute(WfConstant.PRINT_BUFFER, variables);
 
        } catch (Exception e) {
        	e.printStackTrace();
            log.error("转换模版文件出现错误"+e);
        }
		return "gzViewFb";
	}
	
	
    /**
     * ntko控件套打供应设施许可标识
     * @return
     */
    public String printnewGyssxkbs() throws Exception{
        try {
            String ssylbid=getRequest().getParameter("ssylbid");
            ywRqQyjyxkService.getSsylbForm(form);
            YwRqRqssylb sslyb=null;
            if(StringUtils.isNotBlank(ssylbid)){
                 sslyb=ywRqQyjyxkService.getSsylb(Long.valueOf(ssylbid));
                 if(sslyb!=null){
             	   if(sslyb.getBszsbh() == null){
     	            ywRqQyjyxkService.createZsbh(form,2,String.valueOf(form.getSsylbid()),false);
	     	          sslyb.setBszsbh(form.getBszsbh());
	     	            //form.setBszsbh(form.getZsbh() + "-000");
	     	        }else{
	     	    	   if(sslyb.getBszsbh().indexOf("null")>=0){
	     	    		   ywRqQyjyxkService.createZsbh(form,2,String.valueOf(form.getSsylbid()),false);
	     	    		  sslyb.setBszsbh(form.getBszsbh());
	     				}
	     	       }
                 }
            }
            this.dateUtil();    //设置有效时间
            if(form.getBszsbh() == null){
                ywRqQyjyxkService.createZsbh(form,2,ssylbid,false);
            }
            ywRqQyjyxkService.saveSsylb(form,ssylbid);
            String tempPath="Templates/rqjyxk/rqjyxk.xls";
            logger.info("打印经营许可证的文件路径"+tempPath);
       
           String context=getRequest().getSession().getServletContext().getRealPath("");
           tempPath=this.ywRqQyjyxkService.writeSslybData(sslyb,context,form);
           
           getRequest().setAttribute("templateFilePath",tempPath);
           logger.info("返回设施一览表文件路径"+tempPath);
       } catch (Exception e) {
           log.error("转换模版文件出现错误");
       }
       return "printJyxkfbzs";
    }
	
	
	/**
	 * 套打经营许可证副本
	 * @return
	 * @throws ParseException 
	 */
	public String printJyxkzfb() throws ParseException{
	    List<YwComSjclForm> ycsList = ywComSjclService.getList(this.getTemplateCode(), id, "燃气经营许可证（副本）");
        if(ycsList != null && ycsList.size() > 0){
            fbPath = ycsList.get(0).getFilepath();
        }
        //根据附件获取副本的值
        YwRqQyjyxkfbForm yrf = ywRqQyjyxkService.getYwRqQyjyxkfb(this.getSysRealPath(),fbPath,id);
        fb = yrf;
       if(StringUtils.isNotBlank(fb.getZczb())){
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
       if(StringUtils.isNotBlank(form.getZsbh())){
           fb.setYyzzzch(form.getZsbh());//证书编号
       }
       if(StringUtils.isNotBlank(form.getGszcdjh())){
           fb.setYyzzzch(form.getGszcdjh());//营业号
       }
       if(form.getZsbh()==null){
           ywRqQyjyxkService.createZsbh(form,1,null,false);
       }
       
       //发证日期
       if(StringUtils.isNotBlank(fb.getFzrq())){
           DateUtilsEX.convertDate2Chinese(new Date());
       }
       
       String hjmc=getRequest().getParameter("hjmc");
       getRequest().setAttribute("hjmc", hjmc);
       fb.setXkzbh(form.getZsbh());
		if(StringUtils.isNotBlank(fb.getZczb())){//注册资本设置
		   String zczb=fb.getZczb();
		   if(zczb.indexOf("元")<0){
		       fb.setZczb(zczb+"万元");
		   }
		}
		if(StringUtils.isNotBlank(form.getGszcdjh())){
	           fb.setYyzzzch(form.getGszcdjh());
	      }
		if(form.getZsbh()==null){
	           ywRqQyjyxkService.createZsbh(form,1,null,false);
	           ywRqQyjyxkService.saveQyjyxk(form,1);//保存证书
	     }
	     fb.setXkzbh(form.getZsbh());  
		 //ywRqQyjyxkService.saveYwRqQyjyxkfb(this.getSysRealPath()+fbPath, fb);
		return "printJyxkzfb";
	}
	
	/**
	 * 许可标识盖章
	 * @return
	 */
	  public String gzViewGyssxkbs(){ 
		  try {
	            String ssylbid=getRequest().getParameter("ssylbid");
	            ywRqQyjyxkService.getSsylbForm(form);
	            YwRqRqssylb sslyb=null;
	            if(StringUtils.isNotBlank(ssylbid)){
	                 sslyb=ywRqQyjyxkService.getSsylb(Long.valueOf(ssylbid));
	                 if(sslyb!=null){
	             	   if(sslyb.getBszsbh() == null){
	     	            ywRqQyjyxkService.createZsbh(form,2,String.valueOf(form.getSsylbid()),false);
		     	          sslyb.setBszsbh(form.getBszsbh());
		     	            //form.setBszsbh(form.getZsbh() + "-000");
		     	        }else{
		     	    	   if(sslyb.getBszsbh().indexOf("null")>=0){
		     	    		   ywRqQyjyxkService.createZsbh(form,2,String.valueOf(form.getSsylbid()),false);
		     	    		  sslyb.setBszsbh(form.getBszsbh());
		     				}
		     	       }
	                 }
	            }
	            this.dateUtil();    //设置有效时间
	            if(form.getBszsbh() == null){
	                ywRqQyjyxkService.createZsbh(form,2,ssylbid,false);
	            }
	            ywRqQyjyxkService.saveSsylb(form,ssylbid);
	            String tempPath="Templates/rqjyxk/rqjyxk.xls";
	            logger.info("打印经营许可证的文件路径"+tempPath);
	       
	           String context=getRequest().getSession().getServletContext().getRealPath("");
	           tempPath=this.ywRqQyjyxkService.writeSslybData(sslyb,context,form);
	           
	           getRequest().setAttribute("templateFilePath",tempPath);
	           logger.info("返回设施一览表文件路径"+tempPath);
	       } catch (Exception e) {
	           log.error("转换模版文件出现错误");
	       }
		  return "gzViewGyssxkbs";
	  }
	
	/**
     * 套打供应设施许可标识
     * @return
     */
    public String preViewGyssxkbs(){        //读取设施一览表中的数据
    	String isPrint=this.getRequest().getParameter("isPrint");
        String ssylbid=this.getRequest().getParameter("ssylbid");
    	boolean flag=false;
		if(StringUtils.isNotBlank(isPrint)){
			flag=true;
			//重新生成
			ywRqQyjyxkService.createZsbh(form,2,ssylbid,flag);
		}
        if(form.getBszsbh() == null){
            ywRqQyjyxkService.createZsbh(form,2,ssylbid,flag);
            //form.setBszsbh(form.getZsbh() + "-000");
        }
       
        ywRqQyjyxkService.getSsylbForm(form);
        if(StringUtils.isNotBlank(ssylbid)){
            YwRqRqssylb sslyb=ywRqQyjyxkService.getSsylb(Long.valueOf(ssylbid));
	        String startyear="";
	        String startmonth="";
	        String startday="";
	        String endyear="";
	        String endmonth="";
	        String endday="";
            if(sslyb!=null){
            	if(sslyb.getBszsbh() == null){
     	           ywRqQyjyxkService.createZsbh(form,2,String.valueOf(form.getSsylbid()),flag);
     	          sslyb.setBszsbh(form.getBszsbh());
     	            //form.setBszsbh(form.getZsbh() + "-000");
     	       }else{
     	    	   if(sslyb.getBszsbh().indexOf("null")>=0){
     	    		   ywRqQyjyxkService.createZsbh(form,2,String.valueOf(form.getSsylbid()),flag);
     	    		  sslyb.setBszsbh(form.getBszsbh());
     				}
     	       }
            	  form.setBszsbh(sslyb.getBszsbh());
            }
            if(StringUtils.isNotBlank(sslyb.getFzdate())){
            	String fzdate=sslyb.getFzdate();
            	if(fzdate.length()>=10){
            		startyear=DateUtilsEX.convertYearToChar(Integer.valueOf(fzdate.substring(0,4)));
            		startmonth=DateUtilsEX.convertMonthToChar(Integer.valueOf(fzdate.substring(5,7)));
            		startday=DateUtilsEX.convertDayToChar(Integer.valueOf(fzdate.substring(8,10)));
            		form.setStartday(startday);
            		form.setStartmonth(startmonth);
            		form.setStartyear(startyear);
            		
            	}
            }
            if(StringUtils.isNotBlank(sslyb.getValiddate())){//有效期
            	String validdate=sslyb.getValiddate();
            	if(validdate.length()>=10){
            		endyear=DateUtilsEX.convertYearToChar(Integer.valueOf(validdate.substring(0,4)));
            		endmonth=DateUtilsEX.convertMonthToChar(Integer.valueOf(validdate.substring(5,7)));
            		endday=DateUtilsEX.convertDayToChar(Integer.valueOf(validdate.substring(8,10)));
            		form.setEndday(endday);
            		form.setEndmonth(endmonth);
            		form.setEndyear(endyear);
            	}
            } 
            if(StringUtils.isNotBlank(sslyb.getBszsbh())){
            	   form.setBszsbh(sslyb.getBszsbh());
            }
         
        }
        this.dateUtil();    //设置有效时间
    	String taskId=getRequest().getParameter("taskId");
	  	WfBusInstanceTaskForm instance = wfService.getWfBusInstanceTaskById(Long.valueOf(taskId), this.getLoginUserName());
		String activName=instance.getActivityName();
	    getRequest().setAttribute("hjmc", activName);
	    LoginUserForm uform=(LoginUserForm)this.getRequest().getSession().getAttribute("SES_LOGIN_USER");
	    if(StringUtils.isNotBlank(form.getTemplateCode()) && form.getTemplateCode().contains("qx")){
    		form.setFzjg(uform.getOrg().getOrgName());
    		form.setQu("("+uform.getOrg().getOrgName().substring(0, 1)+")");
		}else{
			form.setFzjg("广州市城市管理委员会");
		}
        return "preViewGyssxkbs";
        }
    
    /**
     * 套打供应设施许可标识
     * @return
     */
    public String printGyssxkbs() throws Exception{
    	/*            String ssylbid=getRequest().getParameter("sslybid");
        //保存设施一览表
        ywRqQyjyxkService.saveSsylb(form,ssylbid);
        if(StringUtils.isNotBlank(form.getGqqy())){
            this.getRequest().setAttribute("ggqylength", form.getGqqy().length());
        }
        if(StringUtils.isNotBlank(form.getAddress())){
           form.setAddresslength(form.getAddresslength());
        }*/
        
        //这里写代码
		//String returnCode = WfUtils.wfBusPrint(form);
		// 获取打印的map对象，并替换案件来源id为案件来源名称
    	
		Map<String, String> variables = new HashMap<String, String>();
    	variables.put("bszsbh", form.getBszsbh());
		variables.put("ssmc", form.getSsmc());
		variables.put("ssaddress", form.getSsaddress());
		variables.put("fzr", form.getFzr());
		variables.put("endyear", form.getEndyear());
		variables.put("endmonth", form.getEndmonth());
		variables.put("endday", form.getEndday());
		variables.put("fzjg", form.getFzjg());
		variables.put("startyear", form.getStartyear());
		variables.put("startmonth", form.getStartmonth());
		variables.put("startday", form.getStartday());
		
		//this.getRequest().setAttribute("templateFilePath", "Templates/rqjyxk/rqssxkbs.doc");
		
		// 重新赋值
//		ServletActionContext.getRequest().setAttribute(
//				WfConstant.PRINT_BUFFER, variables);
		
		
		
		
        
		return "PRINT";
        //ywRqQyjyxkService.saveSsylb(form);
    //return "printGyssxkbs";
    }

	/**
	 * 分页查询
	 */
	@Override
	public String list() throws Exception {
		ywRqQyjyxkService.search(page, form);
		return SUCCESS;
	}

	/**
	 * 新增或修改
	 */
	@Override
	public String input() throws Exception {
	     this.initWfOpinions();
	     getRequest().setAttribute("CurrUserName", this.getLoginUser().getUser().getUserName());
	     
	    List<SysCodeForm> sqdwlx = syscodeService.getItems("YW_SQDW_LX");
	    getRequest().setAttribute("sqdwlx", sqdwlx);
		
	    List<SysCodeForm> ywHbbm = syscodeService.getItems("ALL_HBBM");
		getRequest().setAttribute("ywhbbmList", ywHbbm);
		return INPUT;
	}
	

	
	/**
     * 保存业务并关联流程实例
     */
    public String wfBusSave() {
    	
    	try{
            if (form.getQyid() == null) {
                YwComQyxxForm qyxxForm = qyxxService.getFormBySqdw(form.getSqdw(),form.getTemplateCode());
                if (qyxxForm != null) {
                    WfUtils.renderWfFailtureJson("该企业名称已经存在，请点击选择企业从企业列表中选择该企业！");
                    return null;
                }
            }
        WfBusInstanceTaskForm task = this.wfBusSave((IWfBusClientService)ywRqQyjyxkService, form, YwRqQyjyxk.class.getSimpleName());
        WfUtils.renderWfBusSaveJson(task, form);
    	}catch (Exception e) {
    		e.printStackTrace();
    		WfUtils.renderWfFailtureJson("请检查输入内容长度是否过大!");
		}
        return null;
    }
    
    
    public String wfBusYslTuih() throws Exception {
    	try {
    		ywRqQyjyxkService.wfBusYslTuih(form, this.getLoginUser());
			WfBusSaveResult result = new WfBusSaveResult(true, null);
			result.setTask(new WfBusInstanceTaskForm());
			Struts2Utils.renderJson(result);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
        return null;
    }
    /**
     * 用nokt控件的方式套打经营许可证
     * @return
     */
    public String printnewJyxkz(){
        this.dateUtil();    //设置有效时间
        if(form.getZsbh()==null){
            ywRqQyjyxkService.createZsbh(form,1,null,false);
        }
         String hjmc=getRequest().getParameter("hjmc");
         getRequest().setAttribute("hjmc", hjmc);
         String tempPath="Templates/rqjyxk/rqjyxk.xls";
         logger.info("打印经营许可证的文件路径"+tempPath);
        try {
            //Map<String, String> variables=this.ywRqQyjyxkService.buildMap(form,"jyxkz");
            String context=getRequest().getSession().getServletContext().getRealPath("");
            tempPath=this.ywRqQyjyxkService.writeXkzData(form,context);
            getRequest().setAttribute("templateFilePath",tempPath);
            //getRequest().setAttribute(WfConstant.PRINT_BUFFER, variables);
 
        } catch (Exception e) {
            log.error("转换模版文件出现错误");
        }
        return "printJyxkfbzs";
    }
    
    /**
     * 套打新副本
     * @return
     * @throws ParseException
     */
    public String printnewJyxkfb() throws ParseException{
        this.dateUtil();    //设置有效时间
        List<YwComSjclForm> ycsList = ywComSjclService.getList(this.getTemplateCode(), id, "燃气经营许可证（副本）");
        if(ycsList != null && ycsList.size() > 0){
            fbPath = ycsList.get(0).getFilepath();
        }
        //根据附件获取副本的值
        YwRqQyjyxkfbForm yrf = ywRqQyjyxkService.getYwRqQyjyxkfb(this.getSysRealPath(),fbPath,id);
        fb = yrf;
       if(StringUtils.isNotBlank(fb.getZczb())){
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
       if(StringUtils.isNotBlank(form.getZsbh())){
           fb.setYyzzzch(form.getZsbh());//证书编号
       }
       if(StringUtils.isNotBlank(form.getGszcdjh())){
           fb.setYyzzzch(form.getGszcdjh());//营业号
       }
       if(form.getZsbh()==null){
           ywRqQyjyxkService.createZsbh(form,1,null,false);
       }
       
       //发证日期
       if(StringUtils.isNotBlank(fb.getFzrq())){
           DateUtilsEX.convertDate2Chinese(new Date());
       }
       
       String hjmc=getRequest().getParameter("hjmc");
       getRequest().setAttribute("hjmc", hjmc);
       fb.setXkzbh(form.getZsbh());
        if(StringUtils.isNotBlank(fb.getZczb())){//注册资本设置
           String zczb=fb.getZczb();
           if(zczb.indexOf("元")<0){
               fb.setZczb(zczb+"万元");
           }
        }
        if(StringUtils.isNotBlank(form.getGszcdjh())){
               fb.setYyzzzch(form.getGszcdjh());
          }
        if(form.getZsbh()==null){
               ywRqQyjyxkService.createZsbh(form,1,null,false);
               ywRqQyjyxkService.saveQyjyxk(form,1);//保存证书
         }
        
        if(form.getZsbh()==null){
            ywRqQyjyxkService.createZsbh(form,1,null,false);
        }
        fb.setFbzsbh(form.getZsbh());
         getRequest().setAttribute("hjmc", hjmc);
        String path="Templates/rqjyxk/rqjyxkfb.xls";
        String context=getRequest().getSession().getServletContext().getRealPath("");
        // String path="Templates/rqjyxk/rqjyxkfb.xls";
         logger.info("打印经营许可证的文件路径"+path);
        try {
            //构造燃气设施登记表
    	    Map<String,List<RqssdjbForm>> rqssMap=buildRqssdjs();
    	    //构造瓶装燃气供应站登记表
    	    Map<String,List<PzrqgyzdjbForm>> pzMap=buildPzRqssdjs();
    	    String hasFb="";
    	    List<RqssdjbForm> list=ywRqQyjyxkService.getRqssdjbForm(form,true);
    	    if(list!=null && list.size()>0){
    	    	//没有将是否追加的标志保存到数据库，所以只要有一列设施保存了打印到多少页。就为追加的方式打印
    	    	RqssdjbForm rqss=list.get(0);
    	    	if(StringUtils.isNotBlank(rqss.getPagenum())){
    	    		hasFb="y";
    	    	}
    	    }
    	    if("y".equals(hasFb)){
    	    	 path=ywRqQyjyxkService.writeData(form,fb,context,rqssMap,pzMap);
    	    }else{
    	    	 path=ywRqQyjyxkService.writeData(form,fb,context);
    	    }
            getRequest().setAttribute("templateFilePath",path);
            //getRequest().setAttribute(WfConstant.PRINT_BUFFER, variables);
 
        } catch (Exception e) {
        	e.printStackTrace();
            log.error("转换模版文件出现错误"+e);
        }
        return "printJyxkfbzs";
    }
    

	/**
	 * 保存新增或者修改的Form对象
	 */
	@Override
	public String save() throws Exception {
		ywRqQyjyxkService.save(form);
		return RELOAD;
	}

	/**
	 * 删除一条记录
	 */
	@Override
	public String delete() throws Exception {
		ywRqQyjyxkService.delete(id);
		return RELOAD;
	}
	
	/**
	 * 删除多条记录
	 */
	@Override
	public String deleteMore() throws Exception{
		ywRqQyjyxkService.delete(checkedIds);
		return RELOAD;
	}
	
	/**
	 * 辅助方法，设置开始时间和有效时间    期限是5年
	 */
	public void dateUtil(){
	    Date sys_date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(sys_date);
        //设置当前时间
        if(form.getStartyear() == null){
            form.setStartyear(DateUtilsEX.convertNumber2Chinese(cal.get(Calendar.YEAR)));
            //form.setStartyear(cal.get(Calendar.YEAR)+"");
        }
        if(form.getStartmonth() == null){
            form.setStartmonth(DateUtilsEX.convertNumber2Chinese(cal.get(Calendar.MONTH)+1));
            //form.setStartmonth(cal.get(Calendar.MONTH)+1+"");
        }
        if(form.getStartday() == null){
            form.setStartday(DateUtilsEX.convertNumber2ChineseByDay(cal.get(Calendar.DATE)));
            //form.setStartday(cal.get(Calendar.DATE)+"");
        }
        cal.add(Calendar.YEAR, 5);
        System.out.println(cal.getTime());
        if(form.getEndyear() == null){
            form.setEndyear(DateUtilsEX.convertNumber2Chinese(cal.get(Calendar.YEAR)));
            //form.setEndyear(cal.get(Calendar.YEAR)+"");
        }
        if(form.getEndmonth() == null){
            form.setEndmonth(DateUtilsEX.convertNumber2Chinese(cal.get(Calendar.MONTH)+1));
            //form.setEndmonth(cal.get(Calendar.MONTH)+1+"");
        }
        if(form.getEndday() == null){
            form.setEndday(DateUtilsEX.convertNumber2ChineseByDay(cal.get(Calendar.DATE)));
            //form.setEndday(cal.get(Calendar.DATE)+"");
        }
	}
	
	/**
	 * 准备页面模型
	 */
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = ywRqQyjyxkService.get(id);
		}
		
		else
			form = new YwRqQyjyxkForm();
		if (form.getSarq() == null) {
            form.setSarq(new Date());
        }
		
		if (StringUtils.isBlank(form.getAcceptNo())) {
			String rq = DateUtilsEX.getYearAndMonthAndDay();
        	form.setAcceptNo("gz26"+rq+"XXXXX");
        }
		if (StringUtils.isBlank(form.getCbyw())) {
            WfBusTemplateForm wfBusTemplateForm = wfBusTemplateService.getByTemplateCode(getTemplateCode());
            if (wfBusTemplateForm != null) {
                form.setCbyw(wfBusTemplateForm.getTemplateName());
            }
        }
		
		if (StringUtils.isBlank(form.getSjr())) {
            form.setSjr(this.getLoginUser().getUser().getUserName());
        }
		
		if (StringUtils.isBlank(form.getCbbm())) {
            form.setCbbm("燃气处");
        }
		if (form.getFzjg() == null){
		    form.setFzjg("广州市城市管理委员会");
		}
//		if (form.getZsbh() == null){
//		    ywRqQyjyxkService.createZsbh(form,id,1);
//		    //form.setZsbh("00-0000");
//		}
        try {
            if (form.getSarq() == null) {
                form.setSarq(new Date());
            }
            if (form.getCpsj() == null) {
                form.setCpsj(new Date());
            }
/*            if (form.getDfsj() != null) {
                form.setDfsj(DateUtils.stringToDate(form.getCpsj().toString(), DateUtils.YEAR_MOUTH_DAY_));
            }*/
            if (form.getSqrq() == null) {
                form.setSqrq(new Date());
            }
        } catch (Exception e) {
            // TODO: handle exception
        }    
	}
	
	/**
	 * 经办人办理时候保存证书的内容
	 * @return
	 * @throws IOException 
	 */
	public String printSave() throws IOException{
	    Map map=getMapByRequest(getRequest());
        setValueByMap(form, map);
        String result="true";
        try {
            ywRqQyjyxkService.save(form);
        } catch (Exception e) {
            result="false";
        }
        getResponse().getWriter().print(result);
	    return null;
	}

	/**
	 * 经办人办理时候保存证书的内容
	 * @param jyxkForm
	 * @param map
	 */
	private void setValueByMap(YwRqQyjyxkForm jyxkForm,Map map){
	    String address=(String) map.get("address");
	    String jyfw=(String) map.get("jyfw");
	    String gqqy=(String) map.get("gqqy");
	    String fddbr=(String) map.get("fddbr");
	    String endyear=(String) map.get("endyear");
	    String endmonth=(String) map.get("endmonth");
	    String endday=(String) map.get("endday");
	    String startyear=(String) map.get("startyear");
	    String startmonth=(String) map.get("startmonth");
	    String startday=(String) map.get("startday");
	    String zsbh=(String) map.get("zsbh");
	    String fzjg=(String) map.get("fzjg");
	    jyxkForm.setZsbh(zsbh);
	    jyxkForm.setAddress(address);
	    jyxkForm.setJyfw(jyfw);
	    jyxkForm.setGqqy(gqqy);
	    jyxkForm.setFddbr(fddbr);
	    jyxkForm.setEndyear(endyear);
	    jyxkForm.setEndmonth(endmonth);
	    jyxkForm.setEndday(endday);
	    jyxkForm.setStartday(startday);
	    jyxkForm.setStartmonth(startmonth);
	    jyxkForm.setStartyear(startyear);	
	    jyxkForm.setFzjg(fzjg);
	}
	
	/**
	 * 打印时保存副本
	 * @return
	 */
	public String printSavefb(){
	    //先保存安全负责人法定代表人到form中
	    setJyxkInfo();
	    //构造燃气设施登记表
	    Map<String,List<RqssdjbForm>> rqssMap=buildRqssdjs();
	    //构造瓶装燃气供应站登记表
	    Map<String,List<PzrqgyzdjbForm>> pzMap=buildPzRqssdjs();
	    ywRqQyjyxkService.saveJyxkFb(fb,form,rqssMap,pzMap);
	    return this.preViewJyxkzfb();
	}
	
	/**
	 * 构造燃气设施登记
	 * @return
	 */
	private Map<String,List<RqssdjbForm>> buildRqssdjs(){
	    List<RqssdjbForm> list1=new ArrayList<RqssdjbForm>();
	    List<RqssdjbForm> list2=new ArrayList<RqssdjbForm>();
	    Map<String,List<RqssdjbForm>> map=new HashMap<String,List<RqssdjbForm>>();
	    String[] rqssXh1=getRequest().getParameterValues("rqssXh1");
	    String[] rqssMc1=getRequest().getParameterValues("rqssMc1");
	    String[] rqssDz1=getRequest().getParameterValues("rqssDz1");
	    String[] pagenum1=getRequest().getParameterValues("pagenum1");
	    String[] rownum1=getRequest().getParameterValues("rownum1");
	    String[] rqssSslb1=getRequest().getParameterValues("rqssSslb1");
	    String[] rqssId1=getRequest().getParameterValues("rqssId1");
	    String[] rqssXh2=getRequest().getParameterValues("rqssXh2");
        String[] rqssMc2=getRequest().getParameterValues("rqssMc2");
        String[] rqssDz2=getRequest().getParameterValues("rqssDz2");
        String[] rqssSslb2=getRequest().getParameterValues("rqssSslb2");
        String[] rqssId2=getRequest().getParameterValues("rqssId2");
	    if(rqssMc1!=null && rqssMc1.length>0){
	        RqssdjbForm ssdjbform=null;
    	    for(int i=0;i<rqssMc1.length;i++){
    	        if(StringUtils.isNotBlank(rqssMc1[i])){
        	        String xh=rqssXh1[i];
        	        String mc=rqssMc1[i];
        	        String dz=rqssDz1[i];
        	        String pagenum=pagenum1[i];
        	        String rownum=rownum1[i];
        	        String sslb=rqssSslb1[i];
        	        ssdjbform=new RqssdjbForm();
        	        ssdjbform.setDz(dz);
        	        ssdjbform.setMc(mc);
        	        ssdjbform.setPagenum(pagenum);
        	        ssdjbform.setRownum(rownum);
        	        ssdjbform.setMc(mc);
        	        ssdjbform.setSslb(sslb);
        	        ssdjbform.setXh(xh);
        	        if(StringUtils.isNotBlank(rqssId1[i])){
        	            ssdjbform.setId(Long.valueOf(rqssId1[i]));
        	        }
        	        list1.add(ssdjbform);
    	        }
    	    }
	    }
	    if(rqssMc2!=null && rqssMc2.length>0){
	            RqssdjbForm ssdjbform=null;
	            for(int i=0;i<rqssMc2.length;i++){
	                if(StringUtils.isNotBlank(rqssMc2[i])){
    	                String xh=rqssXh2[i];
    	                String mc=rqssMc2[i];
    	                String dz=rqssDz2[i];
    	                String sslb=rqssSslb2[i];
    	                ssdjbform=new RqssdjbForm();
    	                ssdjbform.setDz(dz);
    	                ssdjbform.setMc(mc);
    	                ssdjbform.setSslb(sslb);
    	                ssdjbform.setXh(xh);
    	                if(StringUtils.isNotBlank(rqssId2[i])){
                            ssdjbform.setId(Long.valueOf(rqssId2[i]));
                        }
    	                list2.add(ssdjbform);
    	           }
	            }
	   }
	    map.put("listRqssdjb1", list1);
	    map.put("listRqssdjb2", list2);
	    return map;
	}
	
	 /**
     * 构造构造瓶装燃气供应站登记表
     * @return
     */
    private Map<String,List<PzrqgyzdjbForm>> buildPzRqssdjs(){
        List<PzrqgyzdjbForm> list1=new ArrayList<PzrqgyzdjbForm>();
        List<PzrqgyzdjbForm> list2=new ArrayList<PzrqgyzdjbForm>();
        List<PzrqgyzdjbForm> list3=new ArrayList<PzrqgyzdjbForm>();
        Map<String,List<PzrqgyzdjbForm>> map=new HashMap<String,List<PzrqgyzdjbForm>>();
        String[] rqssXh1=getRequest().getParameterValues("pzrqXh1");
        String[] rqssMc1=getRequest().getParameterValues("pzrqMc1");
        String[] rqssDz1=getRequest().getParameterValues("pzrqDz1");
        String[] pzrqGyzdj1=getRequest().getParameterValues("pzrqGyzdj1");
        String[] rqssXh2=getRequest().getParameterValues("pzrqXh2");
        String[] rqssMc2=getRequest().getParameterValues("pzrqMc2");
        String[] rqssDz2=getRequest().getParameterValues("pzrqDz2");
        String[] pzrqGyzdj2=getRequest().getParameterValues("pzrqGyzdj2");
        String[] rqssXh3=getRequest().getParameterValues("pzrqXh3");
        String[] rqssMc3=getRequest().getParameterValues("pzrqMc3");
        String[] rqssDz3=getRequest().getParameterValues("pzrqDz3");
        String[] pzrqGyzdj3=getRequest().getParameterValues("pzrqGyzdj3");
        String[] pzrqssId1=getRequest().getParameterValues("pzrqssId1");
        String[] pzrqssId2=getRequest().getParameterValues("pzrqssId2");
        String[] pzrqssId3=getRequest().getParameterValues("pzrqssId3");

        if(rqssMc1!=null && rqssMc1.length>0){
            PzrqgyzdjbForm ssdjbform=null;
            for(int i=0;i<rqssMc1.length;i++){
                if(StringUtils.isNotBlank(rqssMc1[i])){
                    String xh=rqssXh1[i];
                    String mc=rqssMc1[i];
                    String dz=rqssDz1[i];
                    String gyzdj=pzrqGyzdj1[i];
                    ssdjbform=new PzrqgyzdjbForm();
                    ssdjbform.setDz(dz);
                    ssdjbform.setMc(mc);
                    ssdjbform.setGyzdj(gyzdj);
                    ssdjbform.setXh(xh);
                    if(StringUtils.isNotBlank(pzrqssId1[i])){
                        ssdjbform.setId(Long.valueOf(pzrqssId1[i]));
                    }
                    list1.add(ssdjbform);
                }
            }
        }
        if(rqssMc2!=null && rqssMc2.length>0){
            PzrqgyzdjbForm ssdjbform=null;
                for(int i=0;i<rqssMc2.length;i++){
                    if(StringUtils.isNotBlank(rqssMc2[i])){
                        String xh=rqssXh2[i];
                        String mc=rqssMc2[i];
                        String dz=rqssDz2[i];
                        String gyzdj=pzrqGyzdj2[i];
                        ssdjbform=new PzrqgyzdjbForm();
                        ssdjbform.setDz(dz);
                        ssdjbform.setMc(mc);
                        ssdjbform.setGyzdj(gyzdj);
                        ssdjbform.setXh(xh);
                        if(StringUtils.isNotBlank(pzrqssId2[i])){
                            ssdjbform.setId(Long.valueOf(pzrqssId2[i]));
                        }
                        list2.add(ssdjbform);
                   }
                }
       }
        
       if(rqssMc3!=null && rqssMc3.length>0){
            PzrqgyzdjbForm ssdjbform=null;
                for(int i=0;i<rqssMc3.length;i++){
                    if(StringUtils.isNotBlank(rqssMc3[i])){
                        String xh=rqssXh3[i];
                        String mc=rqssMc3[i];
                        String dz=rqssDz3[i];
                        String gyzdj=pzrqGyzdj3[i];
                        ssdjbform=new PzrqgyzdjbForm();
                        ssdjbform.setDz(dz);
                        ssdjbform.setMc(mc);
                        ssdjbform.setGyzdj(gyzdj);
                        ssdjbform.setXh(xh);
                        if(StringUtils.isNotBlank(pzrqssId3[i])){
                            ssdjbform.setId(Long.valueOf(pzrqssId3[i]));
                        }
                        list3.add(ssdjbform);
                   }
                }
       }
        map.put("listPzRqssdjb1", list1);
        map.put("listPzRqssdjb2", list2);
        map.put("listPzRqssdjb3", list3);
        return map;
    }

	/**
	 * 设置经营许可信息
	 */
	private void setJyxkInfo(){
	    String fddbr=getRequest().getParameter("fddbr");
        String fddbrZw=getRequest().getParameter("fddbrZw");
        String fddbrZc=getRequest().getParameter("fddbrZc");
        String zyfzr=getRequest().getParameter("zyfzr");
        String zyfzrZw=getRequest().getParameter("zyfzrZw");
        String zyfzrZc=getRequest().getParameter("zyfzrZc");
        String aqfzr=getRequest().getParameter("aqfzr");
        String aqfzrZw=getRequest().getParameter("aqfzrZw");
        String aqfzrZc=getRequest().getParameter("aqfzrZc");
        String jsfzr=getRequest().getParameter("jsfzr");
        String jsfzrZw=getRequest().getParameter("jsfzrZw");
        String jsfzrZc=getRequest().getParameter("jsfzrZc");
        form.setFddbr(fddbr);
        form.setFddbrZc(fddbrZc);
        form.setFddbrZw(fddbrZw);
        form.setZyfzr(zyfzr);
        form.setZyfzrZc(zyfzrZc);
        form.setZyfzrZw(zyfzrZw);
        form.setAqfzr(aqfzr);
        form.setAqfzrZc(aqfzrZc);
        form.setAqfzrZw(aqfzrZw);
        form.setJsfzr(jsfzr);
        form.setJsfzrZc(jsfzrZc);
        form.setJsfzrZw(jsfzrZw);
	    
	}
	
	/**
	 * 到查看考核文件的页面
	 * @return
	 */
	public String viewkHFile(){
		String sslybid=getRequest().getParameter("ssylbid");
		String filepath="";
		if(StringUtils.isNotBlank(sslybid)){
			YwRqRqssylb ssylb=ywRqQyjyxkService.getSsylb(Long.valueOf(sslybid));
			if(ssylb!=null){
				filepath=ssylb.getFilepath();
				
			}
			
		}
		//String filepaths=getRequest().getParameter("filepath");
		getRequest().setAttribute("filepath", filepath);
		return "viewkHFile";
	}
	
	/**
	 * 将燃气经营许可的考核表写入模版中
	 * @return
	 */
	public String uploadkHFile(){
		String filePath=getRequest().getParameter("filepath");
		String contextpath=getRequest().getSession().getServletContext().getRealPath("");
		//备份下原来的文件防止文件覆盖为空
		String bakdir=contextpath+"/Templates/rqjyxk/ssylb/outfile/bak/"+DateUtilsEX.getCurYear()+DateUtilsEX.getCurMonth();
		String fileNamesuffix=filePath.substring(filePath.lastIndexOf(".")+1,filePath.length());
		String bakname = GetFileName.getFileName(fileNamesuffix);
		String bakfile=bakdir+File.separator+bakname;
		bakfile=bakfile.replace("/",File.separator);
		
		List<Attachment> attachments = this.getAttachmentList();
    	if(attachments != null && attachments.size() > 0){
    		Attachment attachment=attachments.get(0);
    		String dirpath=filePath;
    		filePath=contextpath+File.separator+filePath;
    		try {
    			FileUtil.copyFile(filePath, bakfile);
    		} catch (IOException e) {
    			log.info("备份燃气设施许可考核表失败");
    		}
    		boolean flag=FileUtil.uploadFile(filePath, attachment, true, true);
    		
    		//同时上传一份到另外一台服务器
			SFTPUtil.uploadOtherFile("/"+dirpath, filePath);
    		if(flag){
    			renderJson("{\"success\":true}");
    		}
    	}
		
		return null;
	}
	
	
	
	/**
	 * 获取上传的附件对象列表
	 * @return 附件对象列表
	 */
	public List<Attachment> getAttachmentList(){
		if(attachment != null && attachment.length > 0){
			List list = new ArrayList();
			for(int i=0; i<attachment.length; i++){
				Attachment form = new Attachment();
				form.setFile(attachment[i]);
				form.setFileContentType(attachmentContentType[i]);
				form.setFileFileName(attachmentFileName[i]);
				list.add(form);
			}
			
			return list;
		}
		return null;
	}
	
	/**
	 * 用页面展示导入检查的人员情况
	 * @return
	 */
	public String showCheckData(){
		this.getMapByRequest(this.getRequest());
		String checkData=getRequest().getParameter("checkData");
		getRequest().setAttribute("checkData", checkData);
		
	    return "showData";
	}
	
	
    //获取request对象中所有参数，并设置到map中
    private  Map getMapByRequest(HttpServletRequest request) {
        Map<String, String> map = new HashMap<String, String>();
        Enumeration enu = request.getParameterNames();
        while(enu.hasMoreElements()) {   
            String paraName = (String)enu.nextElement();   
            String paraValue = request.getParameter(paraName).trim(); 
            if(paraValue!=null && !"".equals(paraValue)){
                map.put(paraName, paraValue);
            }
        }  
        return map;
    }   
	
	public YwRqQyjyxkForm getModel() {
		return form;
	}
	
	// 属性getter和setter方法
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getCheckedIds() {
		return checkedIds;
	}

	public void setCheckedIds(Long[] checkedIds) {
		this.checkedIds = checkedIds;
	}
	
	public Page<YwRqQyjyxkForm> getPage() {
		return page;
	}


	public void setPage(Page<YwRqQyjyxkForm> page) {
		this.page = page;
	}

	public YwRqQyjyxkfbForm getFb() {
		return fb;
	}

	public void setFb(YwRqQyjyxkfbForm fb) {
		this.fb = fb;
	}

	public String[] getMj() {
		return mj;
	}

	public void setMj(String[] mj) {
		this.mj = mj;
	}

	public String[] getZw() {
		return zw;
	}

	public void setZw(String[] zw) {
		this.zw = zw;
	}

	public String[] getZc() {
		return zc;
	}

	public void setZc(String[] zc) {
		this.zc = zc;
	}

	public String[] getRqssXh() {
		return rqssXh;
	}

	public void setRqssXh(String[] rqssXh) {
		this.rqssXh = rqssXh;
	}

	public String[] getRqssMc() {
		return rqssMc;
	}

	public void setRqssMc(String[] rqssMc) {
		this.rqssMc = rqssMc;
	}

	public String[] getRqssDz() {
		return rqssDz;
	}

	public void setRqssDz(String[] rqssDz) {
		this.rqssDz = rqssDz;
	}

	public String[] getRqssSslb() {
		return rqssSslb;
	}

	public void setRqssSslb(String[] rqssSslb) {
		this.rqssSslb = rqssSslb;
	}

	public String[] getPzrqXh() {
		return pzrqXh;
	}

	public void setPzrqXh(String[] pzrqXh) {
		this.pzrqXh = pzrqXh;
	}

	public String[] getPzrqMc() {
		return pzrqMc;
	}

	public void setPzrqMc(String[] pzrqMc) {
		this.pzrqMc = pzrqMc;
	}

	public String[] getPzrqDz() {
		return pzrqDz;
	}

	public void setPzrqDz(String[] pzrqDz) {
		this.pzrqDz = pzrqDz;
	}

	public String[] getPzrqGyzdj() {
		return pzrqGyzdj;
	}

	public void setPzrqGyzdj(String[] pzrqGyzdj) {
		this.pzrqGyzdj = pzrqGyzdj;
	}

	public String getFbPath() {
		return fbPath;
	}

	public void setFbPath(String fbPath) {
		this.fbPath = fbPath;
	}
	public void tt()throws Exception {
		int aa;
		aa=1;
	}
	
	 public String downLoadtext() throws Exception {
		//String _qyid =(String)getRequest().getAttribute("qyid");
     String acceptNo=(String)getRequest().getParameter("acceptNo");
     String username=(String)getRequest().getParameter("username");
     String params=(String)getRequest().getParameter("params");
     Long qyid=Long.valueOf(getRequest().getParameter("qyid"));
     String type=getRequest().getParameter("type");
     String id=getRequest().getParameter("id")==null?"0":getRequest().getParameter("id");
     Long ajid=Long.valueOf(id);
     String contextpath=getSession().getServletContext().getRealPath("");
 	 log.info("开始导出许可证审批:"+contextpath);
     String path= ywRqQyjyxkImportservice.exportExcel(qyid, acceptNo, username,params,contextpath,ajid,type);
       BufferedInputStream bis = null;
       BufferedOutputStream bos = null;
       OutputStream fos = null;
       InputStream fis = null;
       HttpServletResponse resp = null;
       HttpServletRequest request = null;
       
       String destUrl = path;
       try {
           resp = ServletActionContext.getResponse();
           request = ServletActionContext.getRequest();
           //设置字符编码格式
           resp.setCharacterEncoding("utf-8");
           try {
            request.setCharacterEncoding("utf-8");
           } catch (Exception e1) {
            e1.printStackTrace();
           } 
           File source = new File(destUrl);
           //resp.reset();
          
           resp.setContentType("application/force-download");
           resp.setHeader("Content-Disposition", "attachment; filename=\""
                   + source.getName() + "\"");
           resp.setHeader("Pragma", "No-cache");
           resp.setHeader("Cache-Control", "no-cache");
           fos = resp.getOutputStream();
           bis = new BufferedInputStream(
                   new FileInputStream(source));
           byte[] content = new byte[5 * 1024];
           int length;
           while ((length = bis.read(content, 0, content.length)) != -1) {
               fos.write(content, 0, length);
           }
           //bos.close();
           bis.close();
           fos.close();
//           fis.close();
       } catch (Exception e) {
           //resp.reset();
           e.printStackTrace();
       } finally {
           if (fos != null) {
               fos.close();
           }
//           if (bos != null) {
//               bos.close();
//           }
           if (fis != null) {
               fis.close();
           }
           if (bis != null) {
               bis.close();
           }
           File targetFl=new File(path);
           //删除临时文件
         PoiExcelSheetCopy.delFile(targetFl);
       }

       // try{
       // ywRqQyjyxkImportservice.exportExcel(1321l, "110711004994", "吴祖伟"
       // ,"dd");
       // }catch(Exception e){
       // e.printStackTrace();
       // }
    
        return null;
   }

	public File[] getAttachment() {
		return attachment;
	}

	public void setAttachment(File[] attachment) {
		this.attachment = attachment;
	}
	
	public void cs() throws Exception{
		try {
			kingdomDataForRqsjService.getRqjyxkDatas("", "", "","","");
			kingdomDataForRqsjService.getRqQyzzDatas("", "", "","","");
			kingdomDataForRqsjService.getGyzDatas("", "", "","","");
			kingdomDataForRqsjService.getJszDatas("", "", "","","");
			kingdomDataForRqsjService.getQxdDatas("", "", "","","");
		} catch (Exception e) {
			log.error(this.getTemplateCode() + "_" + form.getId() + "_" + form.getQyid()+"导入申请表时生成企业和站点xml出错"+SysTraceLogWriter.MESSAGE_SEPARATOR + e.getMessage(), e);
			e.printStackTrace();
		}
	}
}
